package com.sbm.merge.service.impl;

import com.sbm.merge.dao.UserMapper;
import com.sbm.merge.entity.User;
import com.sbm.merge.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname UserServiceImpl
 * @Date 2020/11/18 16:37
 * @Created by 刘
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User getUserById(Integer id) {
        User user = userMapper.selectByPrimaryKey(id.longValue());

        return user;
    }

    @Override
    public List<User> getAllUser() {
        List<User> users = userMapper.selectAll();
        return users;
    }

    @Override
    public void deleteUserById(Integer id) {
        userMapper.deleteByPrimaryKey(id.longValue());
    }

    @Override
    public void updateUser(User user, Integer id) {
        user.setId(id.longValue());
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }
}
